package com.yunsc.admin.controller.media;

import com.yunsc.common.utils.Result;
import com.yunsc.common.utils.SecurityUtil;
import com.yunsc.common.validator.ValidationGroups;
import com.yunsc.media.dto.FileGroupDTO;
import com.yunsc.media.entity.YunscUploadGroupEntity;
import com.yunsc.media.service.YunscUploadGroupService;
import io.swagger.annotations.Api;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * @version: 1.0
 * @Author: adan
 * @description:
 * @date: 2024-01-26 10:54
 */
@Api(tags = "文件接口", value = "文件分组管理")
@RestController
@RequestMapping("files/group")
public class FileGroupController {

    @Resource
    private YunscUploadGroupService uploadGroupService;

    @GetMapping("/list")
    public Result<?> queryFileGroupList() {
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        List<YunscUploadGroupEntity> list = uploadGroupService.queryFileGroupList(currentStoreId);
        return Result.resultList(list);
    }

    @PostMapping("/add")
    public Result<?> addFileGroup(@RequestBody FileGroupDTO fileGroupDTO) {
        Integer currentStoreId = SecurityUtil.getCurrentStoreId();
        uploadGroupService.addFileGroup(fileGroupDTO, currentStoreId);
        return Result.ok();
    }

    @PostMapping("/edit")
    public Result<?> editGroup(@RequestBody @Validated({ValidationGroups.Update.class}) FileGroupDTO fileGroupDTO) {
        uploadGroupService.editFileGroup(fileGroupDTO);
        return Result.ok();
    }

    @PostMapping("/delete")
    public Result<?> removeGroup(@RequestBody @Validated({ValidationGroups.Delete.class}) FileGroupDTO fileGroupDTO) {
        uploadGroupService.removeFileGroup(fileGroupDTO);
        return Result.ok();
    }


}
